/**
  * @title: 等待页
  * @description: 用户登录完之后需要进入等待页等待团长确认之后才可以进入首页
  * @author JUN
  */
<template>
	<view class="waitting page">
		<!-- 背景图片 -->
		<waitting-bg class="bg"></waitting-bg>
		
		<view class="content">
			<h2 class="title">请等待团长确认后再点刷新</h2>
		
			<button class="flash-btn" @click="flash">刷新</button>
		
		</view>
	</view>
</template>

<script>
	import * as api from "@/api/apiList/user/user.js"
	
	import { createNamespacedHelpers } from 'vuex'
	const { mapState,mapMutations } = createNamespacedHelpers('userModule')
	
	import waittingBg from "./components/waittingBg.vue"
	export default{
		components:{
			waittingBg
		},
		data(){
			return{
				member:"",//用户信息
				enterprise:"",//企业信息
			}
		},
		methods:{
			...mapMutations(["GET_enterprise","GET_member"]),
			async API_getMemberInfo(){//获取用户信息接口
				return await api.getMemberInfo()
			},
			async getMemberInfo(){//获取用户信息
				let res = await this.API_getMemberInfo()
				let member = res.data.data.member//用户信息
				let enterprise = res.data.data.enterprise//企业信息
				
				if(res.data.code === 1000){
					this.member = member//用户信息
					this.enterprise = enterprise//企业信息
				}else{
					this.$refs.uToast.show({ //提示
						title: '错误',
						type: 'error'
					})
				}
				this.GET_enterprise(enterprise)
				this.GET_member(member)
			},
			flash(){//刷新页面
				this.getMemberInfo()
			}
		},
		watch:{
			member:{
				handler(value){
					console.log(value.state)
					if(value){
						if(value.state === 1){//待确定
							
						}else if(value.state === 2){//确定
							uni.switchTab({//跳转到首页
							    url: '/pages/home/home'
							});
						}else if(value.state === 3){//已离职
							uni.navigateTo({ //跳转到离开页
								url: '/pages/leave/leave'
							});
						}else if(value.state === 4){//团长
							uni.switchTab({//跳转到首页
							    url: '/pages/home/home'
							});
						}
					}
				},
				immediate:true,
				deep:true
			}
		},
		async created(){
			this.getMemberInfo()
		}
	}
</script>

<style lang="scss" scoped>
	.waitting{
		height: 100%;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		
		.bg {
			//背景
			position: absolute;
			z-index: -999;
			width: 100%;
			height: 100%;
		}
		
		.content{
			position: relative;
			z-index: 1;
			
			.title{
			margin: 20px 0;
			font-size: 28rpx;
			}
			
			.flash-btn{
				background-color: #f43a3d;
				font-size: 24rpx;
				width: 210rpx;
				color: #fff;
			}
			
		}
		
		.loading {
			width: 100%;
			height: 100vh;
			background-color: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
</style>
